<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Postadm extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 */
	public function index(){
		$this->mng_posting();
		//$this->load->view('welcome_message');
	}
	
	public function tulis_posting($mode=""){
		$this->load->helper("xinha");
		if($mode=="error"){
			$pesan="Kesalahan, Field Pada Form posting Harus Diisi";
		}elseif($mode=="sukses"){
			$pesan="Posting Berhasil Disimpan, <a href='".site_url('administrator/mng_berita')."'>View berita</a>";
		}else{
			$pesan="";	
		}
		$data['mode']  = $mode;
		$data['pesan'] = $pesan;
		
		//$this->load->plugin('xinha');
		$data['xinha_inclusion'] = javascript_xinha(array('teks'), 
	                                               array('InsertPicture',
												         'InsertPagebreak',
														 'Template',
														 'CharacterMap',
														 'ImageManager',
														 'ListType',
														 'SuperClean',
														 'TableOperations',
														 'FindReplace',
														 'HorizontalRule'), 
												   "default");
        $this->load->view('admin/postadm/admin-tulis-posting',$data);
    }
	
	function mng_posting($mode="noerror",$cari_kategori="null",$cari_deskripsi="null",$hari="0",$bulan="0",$tahun="0",$page=0){
		if($mode=="error"){
			$pesan="Kesalahan, field pada form berita harus diisi";
		}elseif($mode=="update"){
			$pesan="Data berita berhasil diperbaharui";
		}elseif($mode=="delete"){
			$pesan="Data berita berhasil dihapus";
		}else{
			$pesan="";	
		}

		$cari_kategori 	= mySQL_escape_string($this->input->post('cari_kategori'));
		if($cari_kategori==null) $cari_kategori = "null";
		$cari_deskripsi	= mySQL_escape_string($this->input->post('cari_deskripsi'));
		if($cari_deskripsi==null||$cari_deskripsi=="") $cari_deskripsi = "null";
		if($cari_kategori=="date"){
			$cari_deskripsi = "null";
			$hari			= mySQL_escape_string($this->input->post('hari'));
			$bulan			= mySQL_escape_string($this->input->post('bulan'));
			$tahun			= mySQL_escape_string($this->input->post('tahun'));
			if($hari==null) $hari= "0";
			if($bulan==null) $bulan= "0";
			if($tahun==null) $tahun= "0";
		}else{
			$hari= "0";
			$bulan= "0";
			$tahun= "0";	
		}
		
		$data['kategori'] = $cari_kategori;
		$data['deskripsi'] = $cari_deskripsi;
		$data['hari'] = $hari;
		$data['bulan'] = $bulan;
		$data['tahun'] = $tahun;
		$data['kategori_artikel'] = "Berita";
		
			$this->load->library('pagination');
			//$this->load->model('tbl_article');
			//$banyak = $this->tbl_article->hitung_all($data);
			$base_url = base_url();
			$config['base_url'] = $base_url.'administrator/mng_berita/'.$mode.'/'.$cari_kategori.'/'.$cari_deskripsi.'/'.$hari.'/'.$bulan.'/'.$tahun.'/';
			//$config['total_rows'] = $banyak;
			$config['per_page'] = '15'; 
			$config['cur_page'] = $page;
			$this->pagination->initialize($config);
		$data['mode']  = $mode;
		$data['pesan'] = $pesan;	
		//$data['jumlah'] =$banyak;
		//$data['query']= $this->tbl_article->load_admin($data,$config['cur_page']);
		$this->load->view('admin/postadm/admin-mng-posting',$data);
    }
	
	function add_posting(){
		$judul		= mySQL_escape_string($this->input->post('post_judul'));
		$isi	 	= mySQL_escape_string($this->input->post('post_isi'));
		$status		= mySQL_escape_string($this->input->post('post_status'));
		$tanggal	= mySQL_escape_string($this->input->post('post_tanggal'));
		$kategori	= "Berita";
		$penulis	= "Administrator";
		$config['upload_path'] = './utility/news_pictures';
		$config['allowed_types'] = 'tif|gif|jpg|png|bmp';
		$config['max_size']	= '2000';
		
		$this->load->library('upload', $config);
		if(empty($judul) || empty($isi) || empty($status) || empty($tanggal)){
			redirect('paneladm/postadm/tulis_posting/error');
		}
		if (! $this->upload->do_upload()){
			 redirect('paneladm/postadm/tulis_posting/error');
		}	
		else{
			$file = $this->upload->data();
			$file_name = $file['file_name'];
		}
		$this->load->model('tbl_article');
		$this->tbl_article->add($judul, $isi, $kategori, $status, $tanggal, $penulis, $file_name);
		redirect('paneladm/postadm/tulis_posting/sukses');
	}
	
	
	function view_berita($id){
		$this->load->model('tbl_article');
		$data['query'] = $this->tbl_article->edit($id);	
        $this->load->view('admin/admin-view-berita', $data);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */